<template>
  <div class = "cartcontrol">
    <transition name="move">
      <div
        class = 'cart-decrease'
        v-show = 'food.count>0'
        @click.stop.prevent = 'decreaseCart' transition='move'>
        <div class = 'inner icon-remove_circle_outline'></div>
      </div>
    </transition>
    <div
      class = 'cart-count'
      v-show = 'food.count>0'>{{food.count}}
    </div>
    <div
      class = 'cart-add icon-add_circle'
      @click.stop.prevent  = 'addCart'></div>
  </div>
</template>

<script>
import Vue from 'vue'

export default {
  name: '',
  components: {},
  data() {
    return {}
  },
  props: {
    food: {
      type: Object,
    },
  },
  watch: {},
  methods: {
    addCart(event) {
      if (!this.food.count) {
        Vue.set(this.food, 'count', 1)
      } else {
        this.food.count++
      }
      this.$nextTick(()=>{
        this.$emit('addCart',event.target)
      })
    },
    decreaseCart() {
      if (this.food.count > 0) {
        this.food.count--
      }
    },
  },
  computed: {},
  created() {
  },
  mounted() {
  },
  destroyed() {
  },
}
</script>

<style
  lang = "stylus"
  scoped>
  .cartcontrol
    font-size 0
    .cart-add
      display inline-block
      padding 6px
      line-height 24px
      font-size 24px
      color rgb(0, 160, 220)
    .cart-count
      display inline-block
      vertical-align top
      width 12px
      line-height 24px
      text-align center
      color red
      font-size 12px
      padding-top 6px
    .cart-decrease
      display inline-block
      transition all 0.4s linear
      .inner
        padding 6px
        line-height 24px
        font-size 24px
        color rgb(0, 160, 220)
        transition all 0.4s linear
      &.move-enter,&.move-leave-to
        opacity 0
        transform: translate3d(24px,0,0)
        .inner
          transform rotate(180deg)
</style>
